package com.qdu.mapper;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.qdu.entity.Bussiness;
import com.qdu.entity.Manager;
import com.qdu.entity.Usert;

public interface ManagerMapper {
	
	@Select("select ulevel from usert where uid=#{uid}")
	Integer userstatus(String uid);
	@Select("select * from job j,bussiness b where j.bid = b.bid and j.bid = #{bid}")
	List<Map<String,Object>> getJobByBuss(int bid);
	
	
	@Select("select * from manager where mid=#{mid} ")
	Manager getManagerById(String mid);
	@Select("select * from usert")
	List<Usert> getAll();
	//获得为审核的企业列表
	@Select("select * from bussiness where status=2")
	List<Bussiness> getUnreviewd();
	//获取工作列表-默认排序
	@Select("select jid,b.bid,bcity,jtime,jid,b.bname,jobname,bimg,"
			+ "welfare,jptime,jsalary,jnumber from bussiness b,job j"
			+ " where b.bid = j.bid and b.status!=2 "
		)
	List<Map<String,Object>> getJobList();
	//获取工作列表-时间排序
	@Select("select b.bid,bcity,jtime,jid,b.bname,jobname,bimg,welfare,jptime,jsalary,"
			+ "jnumber from bussiness b,job j "
			+ "where b.bid = j.bid and b.status!=2 ORDER BY jptime DESC "
			)
	List<Map<String,Object>> getJobListByTime();
	
	//获取当前的企业数量
	@Select("select COUNT(bid)'totalBussiness' from bussiness where `status`=1")
	int totalBussiness();
	//获得当前待审核企业数量
	@Select("select COUNT(*) from bussiness WHERE `status`=2")
	int totalUnreviewed();
	
	@Select("select bname,baddress from bussiness WHERE `status`=2")
	List<Map<String,Object>> getUnreviewedList();
	
	//获得管理员的角色
	@Select("select role from roles where rolename=#{username}")
	List<String> selectRoleNamesById(String username);
	
	//删除用户信息
	@Delete("delete FROM usert WHERE uid=#{uid}")
	public int deleteUser(String uid);
	
	//删除对应的用户角色表
	@Delete("delete FROM roles WHERE rolename=#{uid}")
	public int deleteUserRoles(@Param("uid") String uid);
	
	@Update("UPDATE usert SET ulevel = -1 WHERE uid = #{uid} ")
	public int updateUlevel(String uid);
	
	@Update("UPDATE usert SET ulevel = 0 WHERE uid = #{uid} ")
	public int updateUlevelEn(String uid);
	
	@Update("UPDATE roles SET rpassword = #{upwd} WHERE rolename = #{uid} ")
	public int updateRolepwd(@Param("upwd")String upwd,@Param("uid")String uid);
	
	//获取所有工作的筛选列表
	@Select("\r\n"
			+ "select DISTINCT jnumber,bpro,jeducation,jsalary,jptime,jtime,bimg,jobname,bname,welfare "
			+ "from job,bussiness where job.bid = bussiness.bid")
	List<Map<String,Object>> getSelection();
	
	//获得企业信息
	@Select("select * from bussiness where bname=#{bname}")
	List<Map<String,Object>> getBussiness(String bname);
	
	//获得企业信息
	@Select("select * from bussiness")
	List<Map<String,Object>> getAllBussiness();
	
	@Update("update bussiness set status=0 where bid=#{bid}")
	int disOneBuss(String bid);
	
	@Update("update bussiness set status=1 where bid=#{bid}")
	int agreeOneBuss(String bid);
	
	//获得所有招聘人的注册信息
	@Select("select * from bussiness b,hr h where h.bid=b.bid")
	List<Map<String,Object>> getHr();
	
	//获取现有合格企业
	@Select("select bname,b.bid from bussiness b where status=1")
	List<Map<String,Object>> getActivebuss();
	
	//select bname,b.bid,a.batchid,batchname from bussiness b,batch a where status=1 and b.bid = a.bid
	//获取现有合格企业,获得所属企业的部门信息
	@Select("select bname,b.bid,a.batchid,batchname from bussiness b,batch a where status=1 and b.bid = a.bid")
	List<Map<String,Object>> getActivebatch();
	
	@Delete("delete from job where jid = #{jid}")
	int deleteJob(BigInteger jid);
}
